package com.pda.gongpin.presenter;


import com.pda.gongpin.bean.UnshelveBean;
import com.pda.gongpin.contract.UnshelveContract;
import com.pda.gongpin.net.NetUtils;
import com.wangshen.base.net.bean.BaseRowsAppEntity;
import com.wangshen.base.ui.mvp.base.presenter.BasePresenter;

import java.util.List;

import io.reactivex.functions.Consumer;

public class UnshelvePresenter extends BasePresenter<UnshelveContract.View> implements UnshelveContract.Presenter{

    @Override
    public void awaitDismountList(String taskNo) {
        NetUtils.geApi().awaitDismountList(taskNo)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseRowsAppEntity<List<UnshelveBean>>>() {
                    @Override
                    public void accept(BaseRowsAppEntity<List<UnshelveBean>> listBaseRowsAppEntity) throws Exception {
                        getView().setList(listBaseRowsAppEntity.getRows());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }

    @Override
    public void wholePalletDetailList(String taskNo) {
        NetUtils.geApi().wholePalletDetailList(taskNo)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseRowsAppEntity<List<UnshelveBean>>>() {
                    @Override
                    public void accept(BaseRowsAppEntity<List<UnshelveBean>> listBaseRowsAppEntity) throws Exception {
                        getView().setList(listBaseRowsAppEntity.getRows());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }

    @Override
    public void callTakeDown(String taskDetailId, String storageBinId) {
        NetUtils.geApi().callTakeDown(taskDetailId, storageBinId)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseRowsAppEntity<List<UnshelveBean>>>() {
                    @Override
                    public void accept(BaseRowsAppEntity<List<UnshelveBean>> listBaseRowsAppEntity) throws Exception {
                        getView().showMessage(listBaseRowsAppEntity.getMsg());
                        getView().onSuccess();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }
}
